//
//  HEMyServiceCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/9.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMyServiceCell.h"

@interface HEMyServiceCell ()

@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *descLb;
@property (nonatomic, strong) UILabel *timeLb;
  
@end

@implementation HEMyServiceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.contentView.backgroundColor = CViewBgColor;
        
        self.qmui_borderPosition = QMUIViewBorderPositionTop;
        self.qmui_borderWidth = 0.5;
        self.qmui_borderColor = CSplitLineColor;
     
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];
    
    warp.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
    warp.layer.cornerRadius = 10; 

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.height.mas_greaterThanOrEqualTo(120);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
    
    // 商品图片
    _goodsimgView = [UIImageView new];
    _goodsimgView.image = IMAGE_NAMED(@"noImage");
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];

    // 姓名
    _titleLb = [UILabel new];
    _titleLb.text = @"张三";
    _titleLb.font = DYBlodFont(18);
    [warp addSubview:_titleLb];
    
    _descLb = [UILabel new];
    _descLb.text = @"张三";
    _descLb.font = DYFont(16);
    _descLb.numberOfLines = 2;
    [warp addSubview:_descLb];
 
    
    // middle
    UILabel *timeLb = [UILabel new];
    timeLb.text = @"购买日期：";
    timeLb.font = DYBlodFont(16);
    timeLb.textColor = CNavDargGrayColor;
    [warp addSubview: timeLb];
     
    _timeLb = [UILabel new];
    _timeLb.text = @"-";
    _timeLb.font = DYFont(16);
    _timeLb.textColor = CNavDargGrayColor;
    _timeLb.numberOfLines = 0;
    [warp addSubview:_timeLb];
     
    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(warp).mas_offset(15);
       make.left.equalTo(warp).mas_offset(15);
       make.width.height.mas_offset(90);
    }];
    _goodsimgView.layer.masksToBounds = YES;
    _goodsimgView.layer.cornerRadius = 8;

    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(_goodsimgView.mas_top);
       make.left.equalTo(_goodsimgView.mas_right).mas_offset(11);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

    
    [_descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_titleLb);
        make.right.equalTo(warp.mas_right).mas_offset(-10);
    }];
     

    [timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_descLb.mas_bottom).offset(10);
        make.left.equalTo(_titleLb.mas_left);
        make.bottom.equalTo(warp).offset(-10);
    }];
    [timeLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
   
    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_descLb.mas_bottom).offset(10);
        make.left.equalTo(timeLb.mas_right);
        make.right.equalTo(warp).offset(-10);
    }];
     
}

- (void)setModel:(HEServicePackModel *)model {
    _model = model;
    
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage: IMAGE_NAMED(@"noImage")];
//    
    _titleLb.text = model.product_name;
    _descLb.text = model.desc;
    _timeLb.text = [NSDate timestampToDate:model.create_date formaterMode:NSDateFormaterModeDay]; 
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
